﻿@{
    Layout = "~/Views/Shared/_MobileLayout.cshtml";
    ViewBag.Title = "购物车";
    var comboList = ViewBag.ComboList as List<LPY.LeHealth.DTO.Cart>;
    var count = comboList.Count;
}

@section Header{
    <link href="~/Asset/stepwizard.css" rel="stylesheet" />
}

<div class="stepwizard">
    <div class="stepwizard-row">
        <div class="stepwizard-step">
            <button type="button" class="btn btn-primary btn-circle">1</button>
            <p><strong>购物车</strong></p>
        </div>
        <div class="stepwizard-step">
            <button type="button" class="btn btn-default btn-circle">2</button>
            <p>核对订单</p>
        </div>
        <div class="stepwizard-step">
            <button type="button" class="btn btn-default btn-circle">3</button>
            <p>提交订单</p>
        </div>
    </div>
</div>

<div class="panel panel-danger">
    <div class="panel-heading">
        <span class="glyphicon glyphicon-shopping-cart"></span> 购物车
        <span id="price_total" class="pull-right"><strong>总计：0</strong></span>
    </div>
    <div class="panel-body cart-detail">
        <ul id="list" style="list-style: none;padding:0px;">
            @if(count==0)
            {
                <p>购物车还没任何商品，赶快选购套餐吧!</p>
            }

            @if (null != comboList)
{
    for (int i = 0; i < comboList.Count; i++)
    {
        <li id="item_@comboList[i].Id" data-id="@comboList[i].Id">
            <span data-id="@comboList[i].Id" class="cart_remove pomegranage glyphicon glyphicon-remove-circle"></span>
            <span>@comboList[i].Combo.Name</span>
            @*<span class="label label-success">银色，64GB</span>*@
            <span id="item_price_@comboList[i].Id" data-price="@comboList[i].Combo.Price" class="cart-price pomegranage pull-right">
                <strong>@Math.Round(comboList[i].Combo.Price * comboList[i].Count, 2)</strong>
            </span>
            <span class="badge text-danger pull-right" style="margin-right:5px;">
                <i data-id="@comboList[i].Id" class="item_minus fa fa-minus" aria-hidden="true"></i>
                <span id="item_count_@comboList[i].Id" style="padding-left:10px;padding-right:10px;"> @comboList[i].Count </span>
                <i data-id="@comboList[i].Id" class="item_plus fa fa-plus" aria-hidden="true"></i>
            </span>
        </li>
    }
}

        </ul>
    </div>
    @if(count>0)
    {
    <div class="panel-footer">
        <a href="@Url.Action("Order","Mobile")" class="btn btn-info btn-block">结算 <span class="glyphicon glyphicon-circle-arrow-right"></span></a>
    </div>        
    }
    else
    {
            <div class="panel-footer">
        <a href="@Url.Action("Order","Mobile")" class="btn btn-info btn-block disabled">结算 <span class="glyphicon glyphicon-circle-arrow-right"></span></a>
    </div>
    }


</div>

@section Footer{
    <script type="text/javascript">
        //计算总数
        function count_total() {
            var list = $("#list");
            var total = 0;
            var index=1;
            for (var i = 0; i < list.children().length; i++) {
                index = $(list.children()[i]).attr("data-id");
                total =total +parseInt( $("#item_price_" + index).text());
            }
            $("#price_total").html("<strong>总计：" + total.toFixed(2) + "</strong>");
        }

        $(function () {
            //统计总金额
            count_total();

            //数量
            $(".item_plus").click(function () {
                var id = $(this).attr("data-id");
                $.ajax({
                    url: '@Url.Action("CartCount", "Mobile")',
                    type: 'post',
                    data: { id: id, isAdd: true },
                    success: function (data) {
                        if (data.Code == 1) {
                            $("#item_count_" + id).html(data.Data);
                            $("#item_price_" + id).html("<strong>" + (data.Data * $("#item_price_" + id).attr("data-price")).toFixed(2) + "</strong>");
                            count_total();
                        }
                    }
                });
            });
            $(".item_minus").click(function () {
                var id = $(this).attr("data-id");
                $.ajax({
                    url: '@Url.Action("CartCount", "Mobile")',
                    type: 'post',
                    data: { id: id, isAdd: false },
                    success: function (data) {
                        if (data.Code == 1) {
                            $("#item_count_" + id).html(data.Data);
                            $("#item_price_" + id).html("<strong>" + (data.Data * $("#item_price_" + id).attr("data-price")).toFixed(2) + "</strong>");
                            count_total();
                        }
                    }
                });
            });
            //移除
            $(".cart_remove").click(function () {
                var id = $(this).attr("data-id");
                $.ajax({
                    url: '@Url.Action("CartRemove", "Mobile")',
                    type: 'post',
                    data: { id: id },
                    success: function (data) {
                        if (data.Code == 1) {
                            $("#item_" + id).remove();
                            count_total();
                        }
                    }
                });
            });
        });
    </script>
}